<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%--
	打开和提交页面放到一个jsp中,
	如何区分:是打开的页面呢?还是提交的数据呢?
 --%>
<%
	Map paramsMap = request.getParameterMap();
    System.out.println(paramsMap);

	String method = request.getParameter("method");
	System.out.println(request.getMethod() + "-----" + method);
	if("submit".equalsIgnoreCase(method))
	{
		/* 处理提交的数据 */
		String email = request.getParameter("email");
		String password = request.getParameter("password");
		/* 服务器端验证 */
		if(email == null)
		{
			email = "" ; 
		}
		
		if("".equalsIgnoreCase(email))
		{
			out.println("邮箱不能为空");
			return ;
		}
		
		String result = email + "--提交方式:"+ request.getMethod() +"----提交数据--" + password;
		System.out.println("============" + result);
		out.println("ok---------------" + result);
		/* JDBC的代码,入库
		..........*/
		return ; 
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>首页 - ssm</title>
		<script type="text/javascript">
			/* 表单验证 */
			function formVal()
			{
				/* 验证邮箱 */
				var eamilObj = document.getElementById("email");
				if(eamilObj.value == '')
				{
					alert("邮箱必填");
					return false ; 
				}
				return true ; 
			}
		</script>
	</head>
	<body>
		<a href="${pageContext.request.contextPath }/insert.jsp?method=submit">get</a>
		<form method="post" action="${pageContext.request.contextPath }/insert.jsp" onsubmit="return formVal()">
			<input type="hidden" name="method" value="submit">
			<table width="80%" border="1">
				<tr>
					<td>邮箱</td>
					<td><input id="email" type="text" name="email" value=""></td>
				</tr>
				<tr>
					<td>密码</td>
					<td><input type="password" name="password" value=""></td>
				</tr>
				<tr>
					<td colspan="2"><input type="submit" value="提交"></td>
				</tr>
			</table>
		</form>
	</body>
</html>